package com.example.controller;


import com.example.domain.message.MessageConstant;
import com.example.domain.message.RedisMessageConstant;

import com.example.domain.pojo.Order;
import com.example.domain.result.Result;
import com.example.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private JedisPool jedisPool;


    //用户提交预约信息
    @RequestMapping("/submit")
    public Result yuyue(@RequestBody Map map) throws Exception {

       //调用体检服务
        Result result=null;
        try {
            //将用户的预约方式添加到map集合
            map.put("orderType", Order.ORDERTYPE_WEIXIN);
            //将查询结果封装到result里面 远程调用,需要try..catch防止失败
            result=orderService.order(map);
        } catch (Exception e) {
            //远程调用失败
             return new Result(false,MessageConstant.ORDERSETTING_FAIL);
        }
//        map.put("orderType", Order.ORDERTYPE_WEIXIN);
//        //将查询结果封装到result里面 远程调用,需要try..catch防止失败
//        result=orderService.order(map);
        return result;

    }

    //用于体检预约成功,跳转到成功页面,根据订单id查询订单order信息findById
    @RequestMapping("/findById")
    public Result findOrderById(Integer id){
        try {
            Map map= orderService.findOrderById(id);
            return new Result(true,MessageConstant.QUERY_ORDER_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_ORDER_FAIL);
        }
    }

    //用户体检预约成功列表
    @RequestMapping("/orderList")
    public List findOrderList(Integer memberId){ //需要会员id
        List list=orderService.findOrderList(memberId);
        return list;

    }
    //确认预约体检成功 按钮
    @RequestMapping("/updateOrder")
    public Result dealWithSatus(Integer orderId){ //需要会员id
        return orderService.dealWithSatus(orderId);
    }
}
